const crypto = require('crypto')

function hmac_sha512(key, message) {
    const hmac = crypto.createHmac('sha512', key)
    hmac.update(message)
    return hmac.digest('hex')
}

function r() {
    code = {
        "n": 20, "codes": {
            "0": "W",
            "1": "l",
            "2": "k",
            "3": "B",
            "4": "Q",
            "5": "g",
            "6": "f",
            "7": "i",
            "8": "i",
            "9": "r",
            "10": "v",
            "11": "6",
            "12": "A",
            "13": "K",
            "14": "N",
            "15": "k",
            "16": "4",
            "17": "L",
            "18": "1",
            "19": "8"
        }
    }
    for (var e = (arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : "/").toLowerCase(), t = e + e, i = "", n = 0; n < t.length; ++n) {
        var a = t[n].charCodeAt() % code.n;
        i += code.codes[a]
    }
    return i
}

function headers_key() {
    e = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {}
    t = (arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : "/").toLowerCase()
    n = JSON.stringify(e).toLowerCase();
    return hmac_sha512(r(t), t + n).toLowerCase().substr(8, 20)
}

function headers_value() {
    e = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {}
    i = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : ""
    t = (arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : "/").toLowerCase()
    n = JSON.stringify(e).toLowerCase();
    return hmac_sha512(r(t), t + "pathString" + n + i)
}

function headers_qcc(t, window_tid) {
    console.log(t)
    console.log(window_tid)
    key = headers_key(t, undefined);
    value = headers_value(t, undefined, window_tid);
    return [key, value]
}

// //
// //
// api = "/api/search/searchmind?mindkeywords=true&mindtype=9&pagesize=5&person=true&searchkey=qw&suggest=true"
// window_tid = '2d36ec72a7ee5eb4df4b07df760ec650'
// console.log(headers_qcc(api, window_tid))